<?php
/**
 * 将upyun上的文件加入到队列
 */
include_once('../lib/config.php');
include_once('../lib/Db.class.php');
include_once('../lib/Model.class.php');
include_once('../lib/Upyun.class.php');
include_once('../lib/function.php');

list($file, $path) = $argv;
if(!$path) $path = 'images';
$up_path = strtoupper($path);

$redis = new Redis();
$redis->connect(REDIS_IP, "6379");  //php客户端设置的ip及端口
if(!$redis) die('redis connect fail');
$redis->auth(REDIS_PASS);

$headers = array(
    'X-List-Iter' => '',
    'X-List-Limit' => 100,
    'X-List-Order' => 'asc',
);

$upyun = new UpYun(UPYUN_BUCKET_LDM, UPYUN_USER, UPYUN_PASS);

while (true) {
    $stop = $redis->get('LNPAN_QUEUE_STOP2');
    if($stop) {
        die('stop');
    }

    $header_array = array();
    $list = $upyun->getPageList('/'.$path.'/', $headers, $header_array);
    foreach ($list as $item) {
        $redis->rPush('UPYUN_'.$up_path.'_QUEUE', $item['name']);
    }
    
    if($header_array && isset($header_array['x-upyun-list-iter'])) {
        $headers['X-List-Iter'] = $header_array['x-upyun-list-iter'];
    }

    var_dump($header_array['x-upyun-list-iter']);
}
